package com.hk.exception;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

@Data
@AllArgsConstructor
@Slf4j
public class BizException extends RuntimeException {

    private String msg;

    private int code = 500;

    private Boolean success;

    private int messageCode = 500;

    private String message;

    public BizException(Throwable a){
        super("系统异常，请联系管理员");
        this.msg = "系统异常，请联系管理员";
    }

    public  BizException (int code, String msg){
        super(msg);
        this.msg = msg;
        this.code = code;

        this.success = false;
        this.message = msg;
        this.messageCode = code;
    }

    public  BizException(String msg){
        super(msg);
        this.msg = msg;

        this.success = false;
        this.message = msg;
        this.messageCode = code;
    }

    public BizException(String msg, Object... params) {
        super(msg);
        String defMsg = params == null ? "" : Arrays.toString(params);
        msg = msg == null ? defMsg : msg;
        msg = String.format(msg, params);
        this.msg = msg;

        this.success = false;
        this.message = msg;
    }


}
